﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_frmAdTaoDeThi : System.Web.UI.Page
{
    DataClassesDataContext db = new DataClassesDataContext();
    clsTaoDeThi taodethi = new clsTaoDeThi();
    //clsDecon taodecon = new clsDecon();
    protected void Page_Load(object sender, EventArgs e)
    {
        btnThem.Attributes.Add("onclick", "return kiemtranhap();");
       //drlQuytac.SelectedIndex = 1;
      // drlQuytac.SelectedIndex = 0;
        
       //DetailsView1.DataBind();
       
        
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        List<string> dschuong = new List<string>();
        foreach (DataListItem item in DataList1.Items)
        {
            CheckBox chuongcbx = (CheckBox)item.FindControl("cbxChuong");
            HiddenField hdfmachuong=(HiddenField)item.FindControl("hdfValueMachuong");
            if (chuongcbx.Checked)
            {
                dschuong.Add(hdfmachuong.Value);
            }
        }
        
        
        DateTime datetime = new DateTime();
        
        datetime = Convert.ToDateTime(txtDateTimePicker.Text);
        string tendethi = txtTenDT.Text.Trim();
        //string mamon = drlTenmon.SelectedValue;
        string maloptc = drlmaloptc.SelectedItem.Text.Trim();
        string maqt = drlQuytac.SelectedItem.Text.Trim();
        taodethi.ThemDeThi(maqt, tendethi,maloptc,datetime);
        //string machuong = string.Empty;
        //te.sp_LayRDCH(3, "madtcr", "Kho");
        taodethi.TaoDeThi( maqt,dschuong);
        //taodecon.TaoCTDeCon(taodethi.retuMadtmax());
        GridView1.DataBind();
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //txtMaDe.Text = GridView1.SelectedRow.Cells[1].Text;
        txtTenDT.Text = GridView1.SelectedRow.Cells[4].Text;
        drlQuytac.SelectedItem.Text = GridView1.SelectedRow.Cells[2].Text;
        drlTenmon.SelectedItem.Text = GridView1.SelectedRow.Cells[3].Text;
    }

    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        txtTenDT.Text = GridView1.SelectedRow.Cells[4].Text;
        drlQuytac.SelectedItem.Text = GridView1.SelectedRow.Cells[2].Text;
        drlTenmon.SelectedItem.Text = GridView1.SelectedRow.Cells[3].Text;
    }
    protected void drlTenmon_SelectedIndexChanged(object sender, EventArgs e)
    {
        

    }
    protected void drlQuytac_SelectedIndexChanged(object sender, EventArgs e)
    {
        //DetailsView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "MyDelete")
        {
            string madt = Convert.ToString(e.CommandArgument); ;
            DateTime ngaythang = DateTime.Now;
            string ngaygioht = string.Format("{0:M/d/yyyy HH:mm:ss}", ngaythang);
            string Nguoixoa = Session["TenDangNhap"].ToString();
            //Lenh xoa o day

            taodethi.XoaDT(madt, ngaygioht, Nguoixoa);
            GridView1.DataBind();
            //LoadDanhSach(); //Load lai thong tin
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
    }
}
